<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Update extends MY_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->check_authentication(1);
		$this->lang->load('candidate/update', $this->session->userdata['user_lang']);
	}
	
	public function index()
	{
		$data = $_POST;

		if (missing_field($data, array('firstname', 'lastname')))
		{
			formError($this->lang->line('update_missingfield'));
		}
		
		if ($data['birthday'] != '' || $data['birthmonth'] != '' || $data['birthyear'] != '')
		{
			if (!valid_date($data['birthday'].'/'.$data['birthmonth'].'/'.$data['birthyear'])
			|| ($data['birthyear'].'-'.$data['birthmonth'].'-'.$data['birthday'] > date('Y-m-d'))
			)
			{
				formError($this->lang->line('update_invalidbirthday'));
			}
		}
		
		$this->load->model('Candidate_model', 'candidate');
		
		$data['idcandidate'] = $this->session->userdata['idprofile'];
		$data['idmember'] = $this->session->userdata['idmember'];
		checkbox2db(array('idtravel', 'idflit', 'idhomeoffice', 'iddeficiency'), $data);
		
		if ($this->candidate->update($data) === false)
		{
		   formError($this->lang->line('global_systemfail'));
		}
		else
		{
		   $this->session->set_userdata($data);
		   formOK($this->lang->line('update_success'));
		}
	}
}

?>